const a = 1

export { }

// const foo: object = function () { }

const arr1: Array<number> = [1, 2, 3]
const arr2: number[] = [1, 2, 3]

function sum(...args: number[]) {
  return args.reduce((pre, current) => pre + current)
}

const tuple: [number, string] = [18, 'aaa']

// const PostStatus = {
//   'success': 0,
//   'fail': 1,
//   'pending': 2,
// }

const enum PostStatus {
  success,
  fail,
  pending
}

const post = {
  status: PostStatus.success
}


function func1(a: number, b: number = 10, ...rest: number[]) {
  return 'aaa'
}
func1(100, 200)
func1(100)
func1(100, 200, 300)

const func2: (a: number, b: number) => string = function (a: number, b: number): string {
  return 'a'
}

function stringify(value: any) {
  return JSON.stringify(value)
}
stringify('string')
stringify(100)
stringify(null)


let age = 18
age = 'string'





let foo
foo = 100
foo = ''


// const nums = [100, 210, 254, 1552]

// const res = nums.find(i => i > 0)

// const num1 = res as number

// const square = num1 * num1

// const num2 = <number>res



interface Post {
  title: string
  content: string
  subtitle?: string
  readonly summary: string
}
const hello: Post = {
  title: 'hello',
  content: 'world',
  summary: 'hello'
}
hello.summary = 'b'

function printPost(post: Post) {
  console.log(post.title)
  console.log(post.content)
}

printPost(hello)


interface Cache {
  [key: string]: string
}
const cache: Cache = {}
cache.foo = 'value'


// class Person {
//   public name: string // = 'init name'
//   private age: number
//   protected readonly gender: boolean
//   constructor(name: string, age: number) {
//     this.name = name
//     this.age = age
//     this.gender = true
//   }

//   sayHi(msg: string): void {
//     console.log(this.name)
//     console.log(this.age)
//   }
// }

// class Student extends Person {
//   private constructor(name: string, age: number) {
//     super(name, age)
//     console.log(this.gender)
//   }
//   static create(name: string, age: number) {
//     return new Student(name, age)
//   }
// }
// const jack = Student.create('jack',18)

// const tom = new Person('tom', 18)
// console.log(tom.name)
// console.log(tom.age)
// console.log(tom.gender)


interface EatAndRun {
  eat(food: string): void
  run(distance: number): void
}

class Person implements EatAndRun {
  eat(food: string): void {
    console.log(`优雅的进餐:${food}`)
  }

  run(distance: number) {
    console.log(`直立行走：${distance}`)
  }
}

class Animal implements EatAndRun {
  eat(food: string): void {
    console.log(`呼噜呼噜的吃：${food}`)
  }
  run(distance: number) {
    console.log(`爬行：${distance}`)
  }
}


// interface Eat {
//   eat(food: string): void
// }
// interface Run {
//   run(distance: number): void
// }


// class Person implements Eat, Run {
//   eat(food: string): void {
//     console.log(`优雅的进餐:${food}`)
//   }

//   run(distance: number) {
//     console.log(`直立行走：${distance}`)
//   }
// }

// abstract class Animal {
//   eat(food: string): void {
//     console.log(`呼噜呼噜的吃：${food}`)
//   }
//   abstract run(distance: number): void
// }

// class Dog extends Animal {
//   run(distance: number): void {
//     console.log('四脚爬行', distance)
//   }
// }
// const d = new Dog()
// d.eat('aaa')
// d.run(100)


function createNumberArray(length: number, value: number): number[] {
  // 由于 Array 对象创建的是any类型的数组，所以我们可以通过泛型参数的方式给数组指定类型
  return Array<number>(length).fill(value)
}

function createArray<T>(length: number, value: T): T[] {
  return Array<T>(length).fill(value)
}
const res = createArray<string>(3, 'f') // ['f','f','f']






import { camelCase } from 'lodash'

// declare function camelCase(input: string): string

const r = camelCase()



import qs from 'query-string'
qs.parse('')